﻿using System.Windows;
using System.Windows.Input;
using GalaSoft.MvvmLight.Messaging;
using KinectCurve.Entities;
using System;

namespace KinectCurve.View
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {            
            InitializeComponent();
            //uncomment when you want to play
            //this.WindowState = System.Windows.WindowState.Maximized;
            ContentHolder.Children.Add(new Menu());
            MessengerDefinitions();
        }

        /// <summary>
        /// Messenger definitions
        /// </summary>
        private void MessengerDefinitions()
        {
            Messenger.Default.Register<EnumMenu>(this, "menuCommand", input =>
            {
                LoadModule(input);
            });

            Messenger.Default.Register<bool>(this, "getWidthHeight", input =>
            {
                Messenger.Default.Send<double>(ContentHolder.ActualWidth, "widthContent");
                Messenger.Default.Send<double>(ContentHolder.ActualHeight, "heightContent");
            });
        }

        private void Window_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                //TODO: change to menu or pause game?
                LoadModule(EnumMenu.Menu);
                Messenger.Default.Send<EnumGameEnd>(EnumGameEnd.UserAborted, "endGame");
            }
            else
            {
                Messenger.Default.Send<Key>(e.Key, "keyPress");
                //System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " KeyUp: " + e.Key.ToString());
            }
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            Messenger.Default.Send<Key>(e.Key, "keyPress");
            //System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " KeyDown: " + e.Key.ToString());
        }

        /// <summary>
        /// Load moudle
        /// </summary>
        /// <param name="input"></param>
        private void LoadModule(EnumMenu input)
        {
            switch (input)
            {
                case EnumMenu.Game:
                    ContentHolder.Children.Clear();
                    ContentHolder.Children.Add(new Game());
                    break;
                case EnumMenu.Menu:
                    ContentHolder.Children.Clear();
                    ContentHolder.Children.Add(new Menu());
                    break;
                case EnumMenu.Options:
                    ContentHolder.Children.Clear();
                    ContentHolder.Children.Add(new Options());
                    break;
                case EnumMenu.Exit:
                    this.Close();
                    break;
                default:
                    break;
            }
        }
    }
}
